package quiz

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("GET")
        url(value(producer("/api/v3/quizzes/1/assignment/1")
                , consumer(regex("/api/v3/quizzes/\\d+/assignment/\\d+"))))
    }
    response {
        status(200)
        body("""
        [
            {
                "id":1,
                "assignmentId":1,
                "quizId":1,
                "userId":1,
                "userAnswer":"userAnswer",
                "submitTime":123123123,
                "correct":true
            }
        ]
        """)
        bodyMatchers {
            jsonPath('$[*]', byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].assignmentId', byRegex(number()))
            jsonPath('$[*].quizId', byRegex(number()))
            jsonPath('$[*].userId', byRegex(number()))
            jsonPath('$[*].userAnswer', byRegex("[\\s\\S]+"))
            jsonPath('$[*].submitTime', byRegex("[\\s\\S]+"))
            jsonPath('$[*].correct', byRegex(anyBoolean()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}
